package it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyVerticalTable;

import com.google.gwt.user.client.ui.*;
import it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyStackPanel.FStackPanel;



public class FVerticalTable extends FStackPanel
{


    Widget[] headers ;
    int width,height;

    int lastSelectedIndex=-1;

    VerticalTableListenerCollection listenerCollection=new VerticalTableListenerCollection();
    

    public FVerticalTable()
    {
        initGui();
    }




    private void initGui()
    {

      

       
    }


    public void setHeaders(final Widget[] headers)
    {
         this.headers=headers;


         for(int i=0;i<headers.length;i++)
         {
           FColumn column=new FColumn()
           {


               public void onScroll(int scrollPosition)
               {
                   for(int i=0;i<headers.length;i++)
                   {
                        FColumn column = (FColumn)getContent(i);
                        if(column!=this)
                         column.setScrollPosition(scrollPosition); 

                   }
               }



               public void selectItem(int index)
               {

                   if(index==lastSelectedIndex)
                     return;

                   for(int i=0;i<headers.length;i++)
                   {
                        FColumn column = (FColumn)getContent(i);
                        column.getItem(index).setStyleName("FVerticalTable-item-selected");

                        if(lastSelectedIndex!=-1)
                               column.getItem(lastSelectedIndex).setStyleName("FVerticalTable-item");



                   }

                lastSelectedIndex=index;
                listenerCollection.fireOnClick(index);   
               }
           };
           addItem(headers[i],column);

         }


         openItem(0);


   
    }

    public void addItem(Widget[] items)
       {
            
            for(int i=0;i<headers.length;i++)
            {
                FColumn column = (FColumn)getContent(i);

                column.addItem(items[i]);

            }


       }
    public void removeItem(int index)
          {

               for(int i=0;i<headers.length;i++)
               {
                   FColumn column = (FColumn)getContent(i);

                   column.removeItem(index);

               }


          }



    public void setItemsHeight(int height)
              {

                   for(int i=0;i<headers.length;i++)
                   {
                       FColumn column = (FColumn)getContent(i);

                       column.setItemHeight(height);

                   }


              }
    public void setArrowWidgetsUrl(String upArrowUrl, String downArrowUrl)
    {
        for(int i=0;i<headers.length;i++)
         {
             FColumn column = (FColumn)getContent(i);

            column.setArrowWidgetsUrl(upArrowUrl,downArrowUrl);

          }
    }



    public void setRowSpacing(int rowSpacing)
    {
         for(int i=0;i<headers.length;i++)
         {
             FColumn column = (FColumn)getContent(i);

            column.setRowSpacing(rowSpacing);

          }
    }

    public void setArrowsSize(int width,int height)
    {
       for(int i=0;i<headers.length;i++)
         {
             FColumn column = (FColumn)getContent(i);

            column.setArrowsSize(width,height);

          }
    }
     public void animStarted()
     {
       for(int i=0;i<headers.length;i++)
         {
             FColumn column = (FColumn)getContent(i);
            column.upTimer.cancel();
             column.downTimer.cancel();
            column.block=true;
         

          }
    }

    public void animFinished()
    {
       for(int i=0;i<headers.length;i++)
         {
             FColumn column = (FColumn)getContent(i);

              column.upTimer.cancel();
             column.downTimer.cancel();
            column.block=false;
            column.updateGui();

          }
    }

   public void selectItem(int index)
   {
      for(int i=0;i<headers.length;i++)
         {

              FColumn column = (FColumn)getContent(i);

             if(lastSelectedIndex!=-1)
             {
                 column.getItem(lastSelectedIndex).setStyleName("FVerticalTable-item");

             }

            
             column.getItem(index).setStyleName("FVerticalTable-item-selected");



           }
          ((FColumn)getContent(getOpenItemIndex())).ensureVisibleItem(index);

          lastSelectedIndex=index;
   }
    public void addVerticalTableListener(VerticalTableListener listener)
      {
          listenerCollection.add(listener);
      }

    private void getOpenedContent() {
    }




}